Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PhasedXZGate._unitary_ #4617

Merged
merged 1 commit into from
Nov 2, 2021
Merged

Conversation

maffoo
Copy link
Contributor

@maffoo maffoo commented Nov 2, 2021

Fixes #3965. Fixes #4434.

@maffoo maffoo requested review from cduck, vtomole and a team as code owners November 2, 2021 03:20
@maffoo maffoo requested a review from mpharrigan November 2, 2021 03:20
@CirqBot CirqBot added the size: S 10< lines changed <50 label Nov 2, 2021
@google-cla google-cla bot added the cla: yes Makes googlebot stop complaining. label Nov 2, 2021
@MichaelBroughton MichaelBroughton self-assigned this Nov 2, 2021
Copy link
Collaborator

@MichaelBroughton MichaelBroughton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with some questions.

gate = cirq.PhasedXZGate.from_matrix(unitary)
kraus = cirq.kraus(gate)
assert len(kraus) == 1
cirq.testing.assert_allclose_up_to_global_phase(kraus[0], unitary, atol=1e-8)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: is this tol too high for complex64. I would've expected only around 6-7 decimal digits of reliability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was copy-pasted from other allclose checks in the same module. I'm inclined to keep it for consistency, but we could certainly relax it throughout the module if desired.

np.array([[0, 1], [1j, 0]]),
],
)
def test_from_matrix_close_kraus(unitary: np.ndarray):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add another test that hits cirq.unitary as well ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a test of cirq.unitary: https://github.com/quantumlib/Cirq/blob/master/cirq-core/cirq/ops/phased_x_z_gate_test.py#L196. This worked by decomposition even without a _unitary_ implementation, but other protocols like cirq.kraus didn't.

@maffoo maffoo merged commit 64df1fc into master Nov 2, 2021
@maffoo maffoo deleted the u/maffoo/phased-xz-unitary branch November 2, 2021 06:38
rht pushed a commit to rht/Cirq that referenced this pull request May 1, 2023
harry-phasecraft pushed a commit to PhaseCraft/Cirq that referenced this pull request Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Makes googlebot stop complaining. size: S 10< lines changed <50
Projects
None yet
3 participants